#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .odoo_manager import OdooManager
from .memcache_manager import MemcacheManager


class AppConfig(object):
    """
    功能：单件模式app配置类
    """

    def __init__(self):
        pass

    def __new__(cls, *args, **kwargs):
        if not hasattr(AppConfig, "_instance"):  # 反射
            AppConfig._instance = object.__new__(cls)
        return AppConfig._instance

    def get_app_config(self):
        """获取微信小程序app_id和secret配置"""
        odoo = OdooManager().get_instance()
        mc = MemcacheManager()
        app_id = mc.get('app_id')
        app_secret = mc.get('app_secret')
        if not app_id or not app_secret:
            app_id = odoo.env['ir.config_parameter'].get_param('wx.miniapp.appId', False)
            app_secret = odoo.env['ir.config_parameter'].get_param('wx.miniapp.appSecret', False)
            mc.set('app_id', app_id)
            mc.set('app_secret', app_secret)
        return app_id, app_secret
